/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * ProgressPanel.java
 *
 * Created on Jun 26, 2011, 6:45:04 PM
 */
package ua.pp.bizon.yandex.nb;

import ua.pp.bizon.yandex.api.impl.EventSupport.ChangeListener;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 * 
 * @author Bizon
 */
public class ProgressPanel extends javax.swing.JPanel implements ChangeListener {

	private static final long serialVersionUID = 1470578387890084153L;

	/** Creates new form ProgressPanel */
	public ProgressPanel() {
		initComponents();
		data = new AddPhotosDialogData();
		data.addListener(this);
		repeatCheckBox.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				data.setRepeatOnErrorNoFire(repeatCheckBox.isSelected());
			}
		});
	}

	private AddPhotosDialogData data = new AddPhotosDialogData();

	public AddPhotosDialogData getData() {
		return data;
	}

	public void setData(AddPhotosDialogData data) {
		this.data = data;
	}

	public void dataChanged() {
		firstLineLabel.setText("Copy from " + data.getFrom() + " to " + data.getTo());
		secondLineLabel.setText("done " + data.getCountdone() + " of " + data.getTotalcount());
		progressBar.setValue(data.getCountdone());
		progressBar.setMaximum(data.getTotalcount());
		progressBar.setMinimum(0);
		repeatCheckBox.setSelected(data.isRepeatOnError());
	}

	/**
	 * This method is called from within the constructor to initialize the form.
	 * WARNING: Do NOT modify this code. The content of this method is always
	 * regenerated by the Form Editor.
	 */
	// <editor-fold defaultstate="collapsed"
	// <editor-fold defaultstate="collapsed"
	// desc="Generated Code">//GEN-BEGIN:initComponents
	private void initComponents() {

		firstLineLabel = new javax.swing.JLabel();
		progressBar = new javax.swing.JProgressBar();
		secondLineLabel = new javax.swing.JLabel();
		repeatCheckBox = new javax.swing.JCheckBox();
		cancelButton = new javax.swing.JButton();

		firstLineLabel.setText("Copy <from> to <to>");

		secondLineLabel.setText("Done: # of #");

		repeatCheckBox.setText("repeat on errors");

		cancelButton.setText("Cancel");
		cancelButton.addActionListener(new java.awt.event.ActionListener() {
			public void actionPerformed(java.awt.event.ActionEvent evt) {
				cancelButtonActionPerformed(evt);
			}
		});

		javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
		this.setLayout(layout);
		layout.setHorizontalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addGroup(
								layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addComponent(progressBar, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 380,
												Short.MAX_VALUE)
										.addGroup(
												layout.createSequentialGroup().addComponent(secondLineLabel)
														.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 144, Short.MAX_VALUE)
														.addComponent(cancelButton).addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
														.addComponent(repeatCheckBox)).addComponent(firstLineLabel)).addContainerGap()));
		layout.setVerticalGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGroup(
				layout.createSequentialGroup()
						.addContainerGap()
						.addComponent(firstLineLabel)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addComponent(progressBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE,
								javax.swing.GroupLayout.PREFERRED_SIZE)
						.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
						.addGroup(
								layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
										.addGroup(
												layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE).addComponent(secondLineLabel)
														.addComponent(repeatCheckBox)).addComponent(cancelButton))
						.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)));
	}// </editor-fold>//GEN-END:initComponents

	private void cancelButtonActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_cancelButtonActionPerformed
		if (job != null) {
			job.cancel();
		}
	}// GEN-LAST:event_cancelButtonActionPerformed

	// Variables declaration - do not modify//GEN-BEGIN:variables
	private javax.swing.JButton cancelButton;
	private javax.swing.JLabel firstLineLabel;
	private javax.swing.JProgressBar progressBar;
	private javax.swing.JCheckBox repeatCheckBox;
	private javax.swing.JLabel secondLineLabel;

	// End of variables declaration//GEN-END:variables

	private AddPhotosController job;

	public void setJob(AddPhotosController addPhotosController) {
		this.job = addPhotosController;

	}
}
